package org.example.tulurouter.config;

import jakarta.annotation.Resource;
import org.example.tulurouter.interceptor.LoginTokenintercepter;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 配置类
 */
@Configuration
public class MyWebConfigurer implements WebMvcConfigurer {
    @Resource
    private LoginTokenintercepter loginTokenintercepter;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")      // 所有接口
                .allowCredentials(true)     // 是否发送 Cookie
                .allowedOriginPatterns("*")     // 支持域
                .allowedMethods("*")
                .allowedHeaders("*")
                .exposedHeaders("*")
                .maxAge(3600);

        }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginTokenintercepter).addPathPatterns("/**")
                .excludePathPatterns("/user/login",
                        "/user/register",
                        "/api/checkCode",
                        "/user/findpassword",
                        "/user/info",
                        "/user/getMyavatar",
                        "/Userchat",
                        "/user/confirmFind",
                        "/user/SecKillForRedis");
    }



    /*
     *addResourceHandler:访问映射路径
     *addResourceLocations:资源绝对路径
     */
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/productAvatar/**").addResourceLocations("file:D:\\photo\\Onlinebooks_photo\\");
//    }
}